/*
 * s_user_sys.c
 *
 *  Created on: Sep 4, 2020
 *      Author: hemingway
 */
#include "s_user_sys.h"

#include "s_sc_uart.h"
#include "h_cc2640r2f_uart.h"
#include "h_cc2640r2f_gpio.h"
#include "h_cc2640r2f_iic.h"

#include "h_cc2640r2f_simpletime.h"

//#include "s_csam_data.h"
#include <stdio.h>
//#include "s_sd3077.h"

#include "h_cc2640r2f_define.h"
//#include "s_zcs_totp.h"
//#include "s_csam_driver.h"
#include "flash_interface.h"
#include "simple_peripheral_oad_offchip.h"

//#include "s_msg_mcu.h"

#include "s_common_loopClock.h"

#include "s_common_message.h"

static signed char init_rslt;

unsigned char isPeripheralActive = 0U;

signed char S_Sys_Init_In_Main(void)
{
    isPeripheralActive = 1U;
//    isMCUCommunicateEnable = 1U;

//    init_rslt += S_SC_UART_Init();
//    init_rslt += H_CC2640R2F_GPIO_Init();
    init_rslt += H_CC2640R2F_UART_Init();

//    init_rslt += H_CC2640R2F_IIC_Init();

    s_common_loopClock_init();
    s_common_message_init();

    flash_open();
    flash_close();

    return 0;
}


signed char S_Sys_Init_Before_BLEInit(void)
{
//    H_CC2640R2F_GPIO_IRQ_Enable();
#if LOCK_BOARD_RELEASE
    isMCUCommunicateEnable = 0U;
#endif
    H_CC2640R2F_UART_RxEnable();
    return 0;
}


//signed char s_sys_peripheral_halt(void)
//{
//    if(isPeripheralActive) {
//        if(!is_s_sc_uart_fifo_empty()) {
//#if LOCK_BOARD_RELEASE
//            s_sc_uart_deinit();
//#endif
////            s_csam_driver_vcc_low();
////            H_CC2640R2F_UART_RxDisable();
////            H_CC2640R2F_IIC_Deinit();
////            H_CC2640R2F_GPIO_OutputSet(S_WAKE_UP_OUT, 1);
////            isPeripheralActive = 0U;
////            isMCUCommunicateEnable = 0U;
//            // Clear open rslt
////            s_csam_data_set_open_flag(s_csam_data_last_open_flag_disable);
////            s_csam_data_set_open_rslt(s_csam_data_last_open_faild);
////        } else {
////            s_ask_halt_peripheral();
////        }
//        }
//    }
//    return 0;
//}

//signed char s_sys_peripheral_active(void)
//{
//    if(!isPeripheralActive) {
////        s_csam_driver_vcc_high();
//#if LOCK_BOARD_RELEASE
//        s_sc_uart_reinit();
//#endif
////        H_CC2640R2F_IIC_Init();
////        isPeripheralActive = 1U;
//        return 0;
//    }
//    return 1;
//}


